package com.yuanrui.practice.server.subject;


import com.yuanrui.practice.api.vo.PracticeSubjectOptionVO;
import com.yuanrui.practice.server.dao.SubjectRadioDao;
import com.yuanrui.practice.server.entity.po.SubjectOptionPO;
import com.yuanrui.practice.server.entity.po.SubjectRadioPO;
import com.yuanrui.practice.server.enums.IsDeletedFlagEnum;
import com.yuanrui.practice.server.enums.SubjectInfoTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * 单选题目策略类
 */
@Component
public class RadioTypeHandler implements SubjectTypeHandler {

    @Resource
    private SubjectRadioDao subjectRadioDao;

    @Override
    public SubjectInfoTypeEnum getSubjectType() {
        return SubjectInfoTypeEnum.RADIO;
    }


    @Override
    public List<PracticeSubjectOptionVO> query(Long subjectId) {
        List<PracticeSubjectOptionVO> practiceSubjectOptionVOS = new LinkedList<>();
        List<SubjectRadioPO> radioPOS = subjectRadioDao.selectBySubjectId(subjectId);
        if (radioPOS.isEmpty()){
            return practiceSubjectOptionVOS;
        }
        radioPOS.forEach(radioPO -> {
            PracticeSubjectOptionVO practiceSubjectOptionVO = new PracticeSubjectOptionVO();
            practiceSubjectOptionVO.setOptionContent(radioPO.getOptionContent());
            practiceSubjectOptionVO.setIsCorrect(radioPO.getIsCorrect());
            practiceSubjectOptionVO.setOptionType(radioPO.getOptionType());
            practiceSubjectOptionVOS.add(practiceSubjectOptionVO);
        });
        return practiceSubjectOptionVOS;
    }
}
